import json
import re

class FrameToJson:
    def __init__(self):
        self.frames=[]
        self.json={"frames":self.frames}

    def append_frame(self,posX:int,posY:int,width:int,height:int,tag:str):
        self.frames.append({
            "posX":posX,
            "posY":posY,
            "width":width,
            "height":height,
            "tag":tag
        })

    def clear(self):
        self.frames.clear()

    def get_json(self)->str:
        return str(json.dumps(self.json)).replace("\n","")


async def extract_jpg(request,save_path="tmp.jpg"):
    img=await request.content.read()
    with open(save_path,"wb") as fw:
        fw.write(img)